
/*
 *  Copyright 2021
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0+
 * License-Filename: LICENSE
 */

/* XXX is this needed when all debugging done? */
#include <stdio.h>
#include <string.h>

#include "arg.h"
#include "cook.h"
#include "emit.h"
#include "load.h"
#include "preen.h"
#include "syntax.h"

extern int pacc_wrap(const char *, char *, size_t, struct s_node **);

int main(int argc, char **argv) {
    char *in;
    off_t size;
    struct s_node *p;

    arg(argc, argv);

    in = load(arg_input(), &size);

    if (!pacc_wrap(arg_input(), in, size, &p))
	return 1;

    if (strchr(arg_dump(), '0')) s_dump(p);
    desugar(p);
    if (strchr(arg_dump(), '1')) s_dump(p);
    preen(p, arg_name());

    save(arg_output());
    emit(p);

    if (arg_defines()) {
	save(arg_defines());
	header(p);
    }

    if (arg_feed()) {
	cook(p);
	if (strchr(arg_dump(), '2')) s_dump(p);
	save(arg_feed());
	emit(p);
    }

    return 0;
}

/* end. */
